﻿#ifndef ACTUATORDEFINE_H
#define ACTUATORDEFINE_H

/**
 * @brief Actuator命名空间定义了所有执行器相关参数
 */
namespace Actuator {

///连接状态，用于执行器和CAN的连接状态判断：
    enum ConnectStatus
    {
        ///无连接
        NO_CONNECT,
        ///CAN通信已连接
        CAN_CONNECTED=0x02,
        ///执行器已连接
        ACTUATOR_CONNECTED=0x04,
    };

    ///通道ID,用于标识执行器图表数据的通道索引：
    enum Channel_ID
    {
        channel_1=0,
        channel_2,
        channel_3,
        channel_4,
        channel_cnt
    };

///错误类型定义，定义了执行器内部和连接等错误代码：
    enum ErrorsDefine
    {
        ERR_NONE = 0,
    ///执行器过压错误
        ERR_ACTUATOR_OVERVOLTAGE=0x01,
    ///执行器欠压错误
        ERR_ACTUATOR_UNDERVOLTAGE=0x02,
    ///执行器堵转错误
        ERR_ACTUATOR_LOCKED_ROTOR=0x04,
    ///执行器过温错误
        ERR_ACTUATOR_OVERHEATING=0x08,
    ///执行器读写错误
        ERR_ACTUATOR_READ_OR_WRITE=0x10,
    ///执行器多圈计数错误
        ERR_ACTUATOR_MULTI_TURN=0x20,
    ///执行器逆变器温度器错误
        ERR_INVERTOR_TEMPERATURE_SENSOR=0x40,
    ///执行器CAN通信错误
        ERR_CAN_COMMUNICATION=0x80,
    ///执行器温度传感器错误
        ERR_ACTUATOR_TEMPERATURE_SENSOR=0x100,
    ///阶跃过大
        ERR_STEP_OVER=0x200,
    ///执行器DRV保护
        ERR_DRV_PROTECTION=0x400,
    ///编码器失效
        ERR_CODER_DISABLED=0x800,
    ///执行器未连接错误
        ERR_ACTUATOR_DISCONNECTION=0x801,
    ///CAN通信转换板未连接错误
        ERR_CAN_DISCONNECTION=0x802,
    ///无可用ip地址错误
        ERR_IP_ADDRESS_NOT_FOUND=0x803,
    ///执行器非正常关机错误
        ERR_ABNORMAL_SHUTDOWN=0x804,
    ///执行器关机时参数保存错误
        ERR_SHUTDOWN_SAVING=0x805,
        ///通信端口已绑定
        ERR_IP_HAS_BIND=0x806,
        ///通信ip地址冲突
        ERR_IP_CONFLICT=0x808,
        ///执行器ID不唯一错误
        ERR_ID_UNUNIQUE=0x807,
        ERR_UNKOWN=0xffff
    };

///在线状态，用于标识执行器是否处于连接状态：
    enum OnlineStatus
    {
        ///在线
        Status_Online=0x01,
        ///不在线
        Status_Offline=0x00,
    };

///开关状态，标识执行器的开关机状态：
    enum SwitchStatus
    {
        ///执行器开启
        ACTUATOR_SWITCH_OFF=0,
        ///执行器关闭
        ACTUATOR_SWITCH_ON=1,
    };

///图表开关，用于标识执行器图表功能的开启或关闭：
    enum ChartSwitchStatus
    {
        ///图表数据功能开启
        CHART_SWITCH_OFF=0,
        ///图表数据功能关闭
        CHART_SWITCH_ON=1,
    };

///电流环图表索引，用于标识电流图表是IQ值还是ID值
    enum CurrnetChart
    {
        IQ_CHART=0,
        ID_CHART=1,
    };
///归零模式，分为手动和自动两种
    enum HomingOperationMode
    {
        ///自动模式
        Homing_Auto=0,
        ///手动模式(推荐)
        Homing_Manual,
    };
///通信方式，可通过以太网或者串口两种方式与执行器通信，初始化执行器控制器时候要指定方式，默认为以太网通信：
    enum CommunicationType
    {
        ///以太网通信
        Via_Ethernet,
        ///串口通信
        Via_Serialport,
    };

    ///
    enum Initlize_state{
        Uninitialized,
        Initialized,
    };


    ///操作标识，标识操作完成，可用于判断执行器控制器的指令执行状态：
    enum OperationFlags
    {
    ///自动识别完成
        Recognize_Finished,
    ///执行器启动完成（如果连接的是多个执行器，会触发多次启动完成信号）
        Launch_Finished,
    ///执行器关闭完成（如果连接的是多个执行器，会触发多次关闭完成信号）
        Close_Finished,
    ///执行器参数保存完成（如果连接的是多个执行器，会触发多次参数保存完成信号）
        Save_Params_Finished,
        ///执行器参数保存失败
        Save_Params_Failed,
    ///暂未实现
        Attribute_Change_Finished,
    };

///执行器模式，标识当前执行器的模式：
    enum ActuatorMode
    {
        Mode_None,
        ///电流模式
        Mode_Cur,
        ///速度模式
        Mode_Vel,
        ///位置模式
        Mode_Pos,
        ///暂未实现
        Mode_Teaching,
        ///profile位置模式，比较于位置模式，该模式有加速减速过程
        Mode_Profile_Pos=6,
        ///profile速度模式，比较于速度模式，该模式有加速减速过程
        Mode_Profile_Vel,
        ///归零模式
        Mode_Homing,
    };

///执行器属性，标识了执行器所有相关属性：
    enum ActuatorAttribute
    {
        ///电流IQ值
        CUR_IQ_SETTING=0x01,
        ///电流比例
        CUR_PROPORTIONAL=0x02,
        ///电流积分
        CUR_INTEGRAL=0x03,
        ///电流ID值
        CUR_ID_SETTING=0x04,
        ///预留
        CUR_MINIMUM=0x05,
        ///预留
        CUR_MAXIMUM=0x06,
        ///预留
        CUR_NOMINAL=0x07,
        ///预留
        CUR_OUTPUT=0x08,
        ///电流环最大速度
        CUR_MAXSPEED=0x09,
        ///当前电流值
        ACTUAL_CURRENT=0x0a,
        ///速度设置
        VEL_SETTING=0x0b,
        ///速度比例
        VEL_PROPORTIONAL=0x0c,
        ///速度积分
        VEL_INTEGRAL=0x0d,
        ///速度环输出最小电流比例
        VEL_OUTPUT_LIMITATION_MINIMUM=0x0e,
        ///速度环输出最大电流比例
        VEL_OUTPUT_LIMITATION_MAXIMUM=0x0f,
        ///速度值
        ACTUAL_VELOCITY=0x10,
        ///位置设置
        POS_SETTING=0x11,
        ///位置比例
        POS_PROPORTIONAL=0x12,
        ///位置积分
        POS_INTEGRAL=0x13,
        ///位置微分
        POS_DIFFERENTIAL=0x14,
        ///位置环输出最小速度比例
        POS_OUTPUT_LIMITATION_MINIMUM=0x15,
        ///位置环输出最大速度比例
        POS_OUTPUT_LIMITATION_MAXIMUM=0x16,
        ///最小位置限制
        POS_LIMITATION_MINIMUM=0x17,
        ///最大位置限制
        POS_LIMITATION_MAXIMUM=0x18,
        ///归零位置
        HOMING_POSITION=0x19,
        ///当前位置
        ACTUAL_POSITION=0x1a,
        ///profile position模式最大速度
        PROFILE_POS_MAX_SPEED=0x1b,
        ///profile position模式加速度
        PROFILE_POS_ACC=0x1c,
        ///profile position模式减速速度
        PROFILE_POS_DEC=0x1d,
        ///profile velocity模式最大速度
        PROFILE_VEL_MAX_SPEED=0x1e,
        ///profile velocity模式加速度
        PROFILE_VEL_ACC=0x1f,
        ///profile velocity模式减速速度
        PROFILE_VEL_DEC=0x20,
        ///图像频率
        CHART_FREQUENCY=0x21,
        ///图像阈值
        CHART_THRESHOLD=0x22,
        ///图像开关
        CHART_SWITCH=0x23,
        ///位置偏移
        POS_OFFSET=0x24,
        ///电压
        VOLTAGE=0x25,
        ///开启或关闭位置限制
        POS_LIMITATION_SWITCH=0x26,
        ///归零最大电流
        HOMING_CUR_MAXIMUM=0x27,
        ///归零最小小电流
        HOMING_CUR_MINIMUM=0x28,
        ///物理最大电流值
        CURRENT_SCALE=0x29,
        ///速度最大电流值
        VELOCITY_SCALE=0x2a,
        ///电流环滤波是否开启
        FILTER_C_STATUS=0x2b,
        ///电流环滤波值
        FILTER_C_VALUE=0x2c,
        ///速度环滤波是否开启
        FILTER_V_STATUS=0x2d,
        ///速度环滤波值
        FILTER_V_VALUE=0x2e,
        ///位置环滤波是否开启
        FILTER_P_STATUS=0x2f,
        ///位置环滤波值
        FILTER_P_VALUE=0x30,
        ///惯量
        INERTIA=0x31,
        ///堵转保护能量
        LOCK_ENERGY=0x32,
        ///执行器温度
        ACTUATOR_TEMPERATURE=0x33,
        ///逆变器温度
        INVERTER_TEMPERATURE=0x34,
        ///执行器保护温度
        ACTUATOR_PROTECT_TEMPERATURE=0x35,
        ///执行器恢复温度
        ACTUATOR_RECOVERY_TEMPERATURE=0x36,
        ///逆变器保护温度
        INVERTER_PROTECT_TEMPERATURE=0x37,
        ///逆变器恢复温度
        INVERTER_RECOVERY_TEMPERATURE=0x38,
        ///预留
        CALIBRATION_SWITCH=0x39,
        ///预留
        CALIBRATION_ANGLE=0x3a,
        ///执行器开关机
        ACTUATOR_SWITCH=0x3b,
        ///执行器固件版本
        FIRMWARE_VERSION=0x3c,
        ///执行器是否在线
        ONLINE_STATUS=0x3d,
        ///执行器Id
        DEVICE_ID=0x3e,
        ///执行器SN号
        SN_ID=0x3f,
        ///执行器当前模式
        MODE_ID=0x40,
        ///错误代码
        ERROR_ID=0x41,
        ///累计运行时间
        CUMULATIVE_TIME=0x42,
        ///电流限制，任何情况下执行器电流的绝对值都不会超过此值
        CURRENT_LIMIT=0x43,
        ///速度限制，任何情况下执行器速度的绝对值都不会超过此值
        VELOCITY_LIMIT=0x44,
        ///抱闸
        ACTUATOR_BRAKE=0x45,
        ///连接执行器的中间板id
        COMMUNICATION_ID=0x46,
        ///初始化状态
        INIT_STATE=0x47,
        ///装载器版本,不可重复读取
        LOADER_VERSION=0x48,
        VERSION_430=0x49,
        FRENQUENCY_430=0x4a,
        ///预留
        RESERVE_0=0x4b,
        ///预留
        RESERVE_1=0x4c,
        ///预留
        RESERVE_2=0x4d,
        ///预留
        RESERVE_3=0x4e,
        ///预留
        RESERVE_4=0x4f,
        ///预留
        RESERVE_5=0x50,
        ///预留
        RESERVE_6=0x51,
        ///预留
        RESERVE_7=0x52,
        ///预留
        RESERVE_8=0x53,
        DATA_CNT=0x54,
        DATA_CHART,///预留
        DATA_INVALID,
    };

    enum Directives
    {
        D_HANDSHAKE=0x00,
        D_READ_VERSION=0x01,
        D_READ_ADDRESS=0x02,
        D_READ_CONFIG=0x03,
        D_READ_CUR_CURRENT=0x04,
        D_READ_CUR_VELOCITY=0x05,
        D_READ_CUR_POSITION=0x06,
        D_SET_MODE=0x07,
        D_SET_CURRENT=0x08,//设置当前q轴电流
        D_SET_VELOCITY=0x09,
        D_SET_POSITION=0x0a,
        D_SET_PAIRS=0x0b,
        D_SET_CURRENT_ID=0x0c,//设置当前d轴电流
        D_SAVE_PARAM=0x0d,//
        D_SET_CURRENT_P=0x0e,//电流环的p
        D_SET_CURRENT_I=0x0f,
        D_SET_VELOCITY_P=0x10,
        D_SET_VELOCITY_I=0x11,
        D_SET_POSITION_P=0x12,
        D_SET_POSITION_I=0x13,
        D_SET_POSITION_D=0x14,
        D_READ_CUR_P=0x15,
        D_READ_CUR_I=0x16,
        D_READ_VEL_P=0x17,
        D_READ_VEL_I=0x18,
        D_READ_POS_P=0x19,
        D_READ_POS_I=0x1a,
        D_READ_POS_D=0x1b,
        D_READ_PROFILE_POS_MAX_SPEED=0x1c,
        D_READ_PROFILE_POS_ACC=0x1d,
        D_READ_PROFILE_POS_DEC=0x1e,
        D_SET_PROFILE_POS_MAX_SPEED=0x1f,
        D_SET_PROFILE_POS_ACC=0x20,
        D_SET_PROFILE_POS_DEC=0x21,
        D_READ_PROFILE_VEL_MAX_SPEED=0x22,
        D_READ_PROFILE_VEL_ACC=0x23,
        D_READ_PROFILE_VEL_DEC=0x24,
        D_SET_PROFILE_VEL_MAX_SPEED=0x25,
        D_SET_PROFILE_VEL_ACC=0x26,
        D_SET_PROFILE_VEL_DEC=0x27,
        D_READ_CURRENT_MAXSPEED=0x28,
        D_SET_CURRENT_MAXSPEED=0x29,
        D_SET_SWITCH_MOTORS=0x2a,
        D_READ_MOTORS_SWITCH=0x2b,
        D_SET_MOTOR_MAC=0x2c,
        D_SET_CURRENT_PID_MIN = 0x2e,//设置电流环的pid的上下限
        D_SET_CURRENT_PID_MAX=0x2f,
        D_SET_VELOCITY_PID_MIN=0x30,
        D_SET_VELOCITY_PID_MAX=0x31,
        D_SET_POSITION_PID_MIN=0x32,
        D_SET_POSITION_PID_MAX=0x33,
        D_READ_CURRENT_PID_MIN=0x34,//读取电流环的pid的上下限
        D_READ_CURRENT_PID_MAX=0x35,
        D_READ_VELOCITY_PID_MIN=0x36,
        D_READ_VELOCITY_PID_MAX=0x37,
        D_READ_POSITION_PID_MIN=0x38,
        D_READ_POSITION_PID_MAX=0x39,
        D_READ_CHANNEL_2=0x3a,
        D_READ_CHANNEL_3=0x3b,
        D_READ_CHANNEL_4=0x3c,
        D_SET_DEVICE_ID=0x3d,
        D_SOFTWARE_CLOSE=0x3e,
        D_SET_CHART_THRESHOLD=0x3f,
        D_SET_CHART_FREQUENCY=0x40,
        D_READ_CHART_THRESHOLD=0x41,
        D_READ_CHART_FREQUENCY=0x42,
        D_CHART_DATA_STATR=0x43,
        D_CAN_CONNECT=0x44,
        D_READ_VOLTAGE=0x45,
        D_CHART_OPEN=0x46,
        D_CHART_CLOSE=0x47,
        D_CHANNEL2_OPEN=0x48,//
        D_CHANNEL2_CLOSE=0x49,//
        D_CHANNEL3_OPEN=0x4a,//
        D_CHANNEL3_CLOSE=0x4b,//
        D_CHANNEL4_OPEN=0x4c,//
        D_CHANNEL4_CLOSE=0x4d,//
        D_READ_CHANNEL_1=0x4e,
        D_SET_VOLTAGE=0x4f,//
        D_CRC_ERROR=0x50,
        D_CHANNEL1_OPEN=0x51,
        D_CHANNEL1_CLOSE=0x52,
        D_READ_CURRENT_SCALE=0x53,
        D_SET_CUR_TRIGGER_MODE=0x54,//
        D_READ_MOTOR_MODE=0x55,
        D_READ_CURRENT_LIMIT=0x59,
        D_SET_CURRENT_LIMIT=0x58,
        D_READ_VELOCITY_LIMIT=0x5b,
        D_SET_VELOCITY_LIMIT=0x5a,
        D_READ_TEMP_MOTOR=0x5f,
        D_READ_TEMP_INVERTER=0x60,
        D_SET_TEMP_PROTECT=0x6b,
        D_READ_TEMP_PROTECT=0x6c,
        D_SET_TEMP_RECOVERY=0x6d,
        D_READ_TEMP_RECOVERY=0x6e,
        D_READ_CUMULATIVE_TIME=0x6f,
        D_SET_INVERTER_TEMP_PROTECT=0x61,
        D_READ_INVERTER_TEMP_PROTECT=0x62,
        D_SET_INVERTER_TEMP_RECOVERY=0x63,
        D_READ_INVERTER_TEMP_RECOVERY=0x64,

        D_SET_FILTER_C_STATUS=0x70,
        D_READ_FILTER_C_STATUS=0x71,
        D_SET_FILTER_C_VALUE=0x72,
        D_READ_FILTER_C_VALUE=0x73,
        D_SET_FILTER_V_STATUS=0x74,
        D_READ_FILTER_V_STATUS=0x75,
        D_SET_FILTER_V_VALUE=0x76,
        D_READ_FILTER_V_VALUE=0x77,
        D_SET_FILTER_P_STATUS=0x78,
        D_READ_FILTER_P_STATUS=0x79,
        D_SET_FILTER_P_VALUE=0x7a,
        D_READ_FILTER_P_VALUE=0x7b,
        D_SET_INERTIA = 0x7c,
        D_READ_INERTIA = 0x7d,
        D_SET_LOCK_ENERGY=0x7e,
        D_READ_LOCK_ENERGY=0x7f,

        D_SET_MAX_POS=0x83,//上下限
        D_SET_MIN_POS=0x84,
        D_READ_MAX_POS=0x85,
        D_READ_MIN_POS=0x86,
        D_SET_HOMING_POS=0x87,
        D_CLEAR_HOMING=0x88,//清除homing相关信息
        D_SET_POS_OFFSET=0x89,
        D_READ_POS_OFFSET=0x8a,
        D_READ_HOMING_LIMIT=0x8b,
        D_SET_HOMING_LIMIT=0x8c,
        D_SET_HOMING_OPERATION=0x8d,
        D_SET_HOMING_MIN=0x8e,
        D_SET_HOMING_MAX=0x8f,
        D_SET_HOMING_CUR_MIN=0x90,
        D_SET_HOMING_CUR_MAX=0x91,
        D_READ_HOMING_CUR_MIN=0x92,
        D_READ_HOMING_CUR_MAX=0x93,
        D_READ_ACTUAL_CVP=0x94,
        D_READ_LOADER_VERSION=0x99,
        D_SWITCH_CALIBRATION=0xa0,
        D_READ_CALIBRATION_SWITCH=0xa1,
        D_START_CALIBRATION=0xa2,
        D_SET_CALIBRATION_ANGLE=0xa3,
        D_READ_CALIBRATION_ANGLE=0xa4,
        D_SWITCH_CALIBRATION_VEL=0xa5,
        D_SET_430_FREQUENCY=0xb3,
        D_READ_430_FREQUENCY=0xb4,
        D_SET_ACTUATOR_BRAKE=0xb6,
        D_READ_ACTUATOR_BRAKE=0xb5,
        D_INIT_430=0xb1,
        D_READ_430_VERSION=0xb2,
        D_READ_RESERVE_0=0xd0,
        D_READ_RESERVE_1=0xd1,
        D_READ_RESERVE_2=0xd2,
        D_READ_RESERVE_3=0xd3,
        D_READ_RESERVE_4=0xd4,
        D_READ_RESERVE_5=0xd5,
        D_READ_RESERVE_6=0xd6,
        D_READ_RESERVE_7=0xd7,
        D_READ_RESERVE_8=0xd8,
        D_READ_LAST_STATE=0xb0,//读取上一次状态（是否正常关机）

        D_IP_BROADCAST=0xc0,//广播查找ip地址
        D_TMP_COMMAND=0xc1,//与中间板通信的协议指令

        D_CLEAR_ERROR=0xfe,//清理错误
        D_CHECK_ERROR=0xff,//错误提示
        DIRECTIVES_INVALID,
    };

}
#endif // ACTUATORDEFINE_H
